# 封装表现层
from common.base import Base,By,open_browser,sleep

class BuyerLoginPage(Base):

    # 封装表现层:制作每个元素的定位器locator
    username_loc = (By.NAME,'login_info')
    password_loc = (By.NAME,'password')
    remember_loc = (By.NAME, 'remember')
    login_loc = (By.CLASS_NAME, 'submit_login')


    # 封装操作层:每一个元素的操作,都写成一个方法
    def input_username(self,text):
       self.send_keys(BuyerLoginPage.username_loc,text)

    def input_password(self, text):
        self.send_keys(BuyerLoginPage.password_loc, text)

    def remember_password(self):
        self.click(BuyerLoginPage.remember_loc)

    def click_login(self):
        self.click(BuyerLoginPage.login_loc)



if __name__ == '__main__':
    login = BuyerLoginPage(open_browser())
    login.get_url('http://localhost/shop/index.php?controller=simple&action=login')
    login.input_username('ceshi2001')
    login.input_password('ceshi2001')
    login.remember_password()
    login.click_login()
    sleep(3)
    login.close_browser()
